package cn.zktr.Personnel.model.service.tanyali;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;

import cn.zktr.Personnel.model.dao.tanyali.EmaDaDao;
import cn.zktr.Personnel.model.dao.tanyali.EmaOutDao;
import cn.zktr.Personnel.model.dao.tanyali.EmaZkzDao;
import cn.zktr.Personnel.model.mappers.tanyali.EmaDaMapper;
import cn.zktr.Personnel.model.pojos.PerEmaDa;

@Service
@Transactional(rollbackOn=Exception.class)
public class EmaDaService {
	@Autowired
	private EmaDaDao dadao;
	@Autowired
	private EmaDaMapper daM;
	@Autowired
	private EmaOutDao outdao;
	@Autowired
	private EmaZkzDao zkzdao;
	
	public Iterable<PerEmaDa> selectFebAll(){
		return dadao.findAll();
	}
	
	/**答案新增
	 * @param agt
	 */
	public void updateda(Integer ZKZID,Integer OUTID,String DAXZT,String DAZHT) {
		PerEmaDa da = new PerEmaDa();
		da.setPerEmaOut(outdao.findById(OUTID).get());
		da.setPerEmaZkz(zkzdao.findById(ZKZID).get());
		da.setDaxzt(DAXZT);
		da.setDazht(DAZHT);
		dadao.save(da);
	}
	
	/**考勤前置
	 * @param ZKZREM
	 * @return
	 */
	public boolean KaoShiQianZhi(String ZKZREM) {
		if(zkzdao.findByZkzrem(ZKZREM)==null) {
			return false;
		}
		JSONArray EmaDa = daM.KaoShiQianZhi(zkzdao.findByZkzrem(ZKZREM).getZkzid());
		if(EmaDa.size()>0)
			return false;
		return true;
	}
}
